<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Akv extends CI_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->library('form_validation');
	}

	public function index(){
		$this->load->model('aktiva','',true);
		$data['aktiva'] = $this->aktiva->get_all();
		$this->load->view('header');
		$this->load->view('menu');
		$this->load->view('aktiva',$data);
		$this->load->view('footer');
	}

	public function insert(){
		$data = array(
				'id_aktiva' 			=> $this->input->post('id_aktiva'),
				'nama' 					=> $this->input->post('nama'),
				'keterangan' 			=> $this->input->post('keterangan'),
				'harga_perolehan'		=> $this->input->post('harga_perolehan'),
				'nilai_residu'			=> $this->input->post('nilai_residu'),
				'umur_ekonomis'			=> $this->input->post('umur_ekonomis'),
				'cabang'				=> $this->input->post('cabang')
			);
		$this->load->model('aktiva','',true);
		$this->form_validation->set_rules('id_aktiva', 'id_aktiva', 'trim|required|is_unique[aktiva.id_aktiva]');
		if ($this->form_validation->run() == FALSE) {
			$menu['error'] = true;
			$this->load->model('aktiva','',true);
			$data['aktiva'] = $this->aktiva->get_all();
			$this->load->view('header');
			$this->load->view('menu');
			$this->load->view('aktiva',$data);
			$this->load->view('footer');
		} else {
			$this->aktiva->insert($data);
			redirect('akv');
		}	
	}

	public function delete($data){
		$this->load->model('aktiva','',true);
		$this->aktiva->delete($data);
		redirect('akv');
	}

	public function edit($id){
		$this->load->model('aktiva','',true);
		$data['detail'] = $this->aktiva->get_by_id($id);
		$data['aktiva'] = $this->aktiva->get_all();
		$this->load->view('header');
		$this->load->view('menu');
		$this->load->view('aktiva',$data);
		$this->load->view('footer');
	}
	public function update(){
		$datainput = array(
				'id_aktiva' 			=> $this->input->post('id_aktiva'),
				'nama' 					=> $this->input->post('nama'),
				'keterangan' 			=> $this->input->post('keterangan'),
				'harga_perolehan'		=> $this->input->post('harga_perolehan'),
				'nilai_residu'			=> $this->input->post('nilai_residu'),
				'umur_ekonomis'			=> $this->input->post('umur_ekonomis'),
				'cabang'				=> $this->input->post('cabang')
			);
			
			
			
		$id = $this->input->post('id_aktiva');
		$this->load->model('aktiva','',true);
		$this->form_validation->set_rules('id_aktiva', 'id_aktiva', 'trim|required');
		if ($this->form_validation->run() == FALSE) {
			$menu['error'] = true;
			$this->load->model('aktiva','',true);
			$data['aktiva'] = $this->aktiva->get_all();
			$this->load->view('header');
			$this->load->view('menu');
			$this->load->view('aktiva',$data);
			$this->load->view('footer');
		} else {
			
		}
		
		$this->aktiva->update($id,$datainput);
			redirect('akv');
	}
}
